package com.lvhx.utils;

import org.springframework.stereotype.Component;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * 内嵌事务处理类，内嵌事务独立于外部事务进行启动、提交或回滚
 * 注意：在内嵌事务中不要对工作单元进行操作，因为所做操作无法回滚
 */
@Component
public class NestableTransactionUnit {

    public static Object execute(TransactionCallback action) {
        TransactionTemplate nestableTransactionTemplate = DataAccessManager.getBeanByName("nestableTransactionTemplate");
        return nestableTransactionTemplate.execute(action);
    }
}
